package com.ydc.ln.tutorial.algorithm.work.zjh;

/**
 * 逆波兰式1,2,+ ==> 1+2
 * 
 * @author ydc
 * @date 下午5:08:35 2013-6-26
 */
public class Ch04 {
    public static void main(String[] args) {
        System.out.println(Ch04.calc("1,2,+"));
    }

    public static int calc(String str) {
        int result = -1;
        String[] params = str.split(",");

        int num1 = Integer.parseInt(params[0]);
        int num2 = Integer.parseInt(params[1]);

        char ope = params[2].toCharArray()[0];

        switch (ope) {
            case '+':
                result = num1 + num2;
                break;
            case '-':
                result = num1 - num2;
                break;
            case '*':
                result = num1 * num2;
                break;
            case '/':
                result = num1 / num2;
                break;
            default:
                break;
        }

        return result;
    }
}
